package com.yundingai.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yundingai.domain.entity.AllMenu;
import com.yundingai.domain.entity.vo.AllMenuVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author liyuxiang
* @description 针对表【all_menu(菜单表：用于动态查询生成后台菜单与动态路由实现)】的数据库操作Mapper
* @createDate 2025-07-16 12:50:48
* @Entity com.yundingai.domain.entity.AllMenu
*/
@Mapper
public interface AllMenuMapper extends BaseMapper<AllMenu> {
    //根据用户名查询用户的所有菜单
    @Select("select m.* from all_menu m join rel_role_menu rm \n" +
            "on m.menu_id = rm.menu_id join all_role r on rm.role_id =r.role_id \n" +
            "join rel_user_role ur on ur.role_id = r.role_id join all_user u\n" +
            " on u.user_id=ur.user_id where u.username =#{username}")
            List<AllMenu> selectAllMenusByUsername(String username);


//修改菜单信息
    void updateMenu(AllMenu allMenu);

    //新增菜单
    void insertMenu(AllMenuVo allMenuVo);

    //角色菜单表插入一条数据
    @Insert("insert into rel_role_menu(role_id,menu_id) values(#{roleId},#{menuId})")
//    @Options(useGeneratedKeys = true, keyProperty = "menuId", keyColumn = "menu_id")
    void insertRoleMenu(Integer roleId,Integer menuId);

}




